home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / recent2 / yamtools.lha / yamtools1.4 / YTArcMove.rexx < prev    next >
OS/2 REXX Batch file  |  1997-03-28  |  17KB  |  458 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /*                            YTARCMOVE                                       */
  4. /*                 Copyright ©1997 by Dick Whiting                            */
  5. /*                                                                            */
  6. /*----------------------------------------------------------------------------*/
  7. /* This script requires YAMTOOLS for it to work. If you don't have YAMTOOLS   */
  8. /* you can get it on Aminet in directory comm/mail. This script allows you    */
  9. /* to archive all selected mail to a folder. This is only really useful from  */
  10. /* the mail list of a SEARCH. Otherwise, use YAM's normal capabilities.       */
  11. /*                                                                            */
  12. /*    WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!WARNING!!         */
  13. /*                                                                            */
  14. /* This one as of Yam 1.3.4 MAY be breaking some of Marcel's rules. I really  */
  15. /* don't know. This allows you to archive FROM ANY folder TO any folder other */
  16. /* than INCOMING,SENT, and OUTGOING. I calculate the new name according to    */
  17. /* what I have surmised Marcel does. No Guarantees that this is entirely      */
  18. /* compatible with the way Marcel intended. Hope so.                          */
  19. /*                                                                            */
  20. /* Version 1.1 of YTARCMOVE includes a test for the YAM version, which kill   */
  21. /* this script if the YAM version is greater than 1.3.x  If (and I don't      */
  22. /* think so) there is a need for this script for later versions of YAM, then  */
  23. /* I will rewrite it as necessary. - Dick                                     */
  24. /*                                                                            */
  25. /*----------------------------------------------------------------------------*/
  26. /*                                                                            */
  27. /* Standard Disclaimer: I wrote it, it works for me, I don't guarantee        */
  28. /* that it will do anything productive for anyone else, etc. etc. ;-)         */
  29. /*                                                                            */
  30. /*HOWEVER, if you DO find a use for it: I homeschool my kids and they         */
  31. /*would love a postcard from where EVER you live.                             */
  32. /*                                                                            */
  33. /*Instant GEOGRAPHY lesson;)                                                  */
  34. /*                                                                            */
  35. /*                                                                            */
  36. /*POSTCARDS:    Dick Whiting                                                  */
  37. /*              28590 S. Beavercreek Rd.                                      */
  38. /*              Mulino, Oregon 97042                                          */
  39. /*              USA                                                           */
  40. /*                                                                            */
  41. /*----------------------------------------------------------------------------*/
  42. /*                                                                            */
  43. /*               Address Bug Reports or Comments to:                          */
  44. /*                Dick Whiting <dwhiting@europa.com>                          */
  45. /*                           11 March 1997                                    */
  46. /*                                                                            */
  47. /******************************************************************************/
  48. /*
  49. $VER: 1.1 Copyright ©1997 by Dick Whiting
  50. $AUTHOR: Dick Whiting
  51. $DESCRIPTION: Archiver-Mover for use with YAMTOOLS
  52. */
  53.  
  54. options results
  55. options failat 21
  56.  
  57. targarch=''
  58. targanum=''
  59. targdir=''
  60.  
  61. parse arg targarch ',' targanum ',' targdir
  62.  
  63. MUIA_List_Format =          0x80423c0a 
  64. MUIA_List_Entries =         0x80421654 
  65. MUIA_VertWeight =           0x804298d0 
  66. MUIA_Window_DepthGadget  =  0x80421923
  67. MUIA_Window_DragBar  =      0x8042045d
  68. MUIA_Window_PublicScreen =  0x804278e4
  69. MUIA_Window_SizeGadget  =   0x8042e33d
  70.  
  71. TRUE=1
  72. FALSE=0
  73.  
  74. MUIV_List_Insert_Active = -1
  75.  
  76. help.SQUIT=''
  77. node.SQUIT=''
  78. help.STEXT=''
  79. node.STEXT=''
  80. help.ARCHF=''
  81. node.ARCHF=''
  82.  
  83. missing='.'
  84. goodver='1.3'                       /* this script is valid for YAM 1.3.x */
  85.  
  86. Address YAMTOOLS
  87.  
  88. Call CheckYam
  89.  
  90. Select
  91.    when targarch='' then do
  92.       Call CheckMailList
  93.       Call ArchWindow
  94.       Call DisplayArchs
  95.    end
  96.    otherwise do
  97.       Call ProcessArchs
  98.    end
  99. end
  100.  
  101.  
  102. exit
  103.  
  104. /**************************************************************************/
  105. /*                Check that there is some mail to process                */
  106. /**************************************************************************/
  107. CheckMailList:
  108.  
  109.    list ID MLST ATTRS MUIA_List_Entries
  110.    mcnt=result
  111.    if mcnt=0 then do
  112.       errmsg='You need to CHOOSE mail to Archive'
  113.       Call ErrorMsg
  114.    end
  115.  
  116. Return
  117.  
  118. /**************************************************************************/
  119. /*                        Display list of Archives                        */
  120. /**************************************************************************/
  121. /*         Don't allow Incoming, Outgoing, Sent as target folders         */
  122. /**************************************************************************/
  123. DisplayArchs:
  124.  
  125.    list ID ALST ATTRS MUIA_List_Entries
  126.    acnt=result
  127.  
  128.    do i=3 to acnt-1
  129.       list ID ALST POS i
  130.       aline=result
  131.       if aline='' then break
  132.       parse var aline arch ',' size ',' file ',' anum ',' rest
  133.       liststr=arch','anum','file
  134.       list ID ARCHF INSERT POS MUIV_List_Insert_Bottom STRING liststr
  135.    end            
  136.    
  137. Return
  138.  
  139. /**************************************************************************/
  140. /*                           Process Archivals                            */
  141. /**************************************************************************/
  142. ProcessArchs:
  143.  
  144.    if targanum < 3 then do
  145.       errmsg="\033b"targarch "\033nis not a valid target for archiving"
  146.       Call ErrorMsg
  147.    end
  148.  
  149.    window ID YTARC close
  150.  
  151.    infotitle='"YAM Tools Info"'
  152.    infotext='\033nDoing Archiving and Moving...'
  153.    infobuttons='"Continue,Interrupt,Abort"'
  154.    showbusy=TRUE
  155.  
  156.    Call InfoWindow
  157.    
  158.    list ID MLST ATTRS MUIA_List_Entries
  159.    mcnt=result
  160.  
  161.    archlist.=missing
  162.    archlist.0=0
  163.    Updlist.=missing
  164.    Updlist.0=0
  165.    acnt=0
  166.  
  167. /**************************************************************************/
  168. /*                     build list of mail to archive                      */
  169. /**************************************************************************/
  170.  
  171.    do i=0 to mcnt-1
  172.       list ID MLST
  173.       mline=result
  174.       if mline='' then break
  175.       parse var mline arch ',' from ',' subj ',' mfor ',' mnum ',' anum ',' file
  176.       acnt=acnt+1
  177.       anum=right(anum,6,'0')
  178.       mnum=right(mnum,6,'0')
  179.       Archlist.0=acnt
  180.       Archlist.acnt=anum mnum file subj
  181.       archlist.0=acnt
  182.       radio ID SQUIT 
  183.       if result~="Continue" then signal ProcessArchsEnd
  184.    end
  185.    Updlist.0=Archlist.0
  186.  
  187.    if acnt=0 then do
  188.       errmsg='You need to SELECT mail to Archive'
  189.       Call ErrorMsg     
  190.    end
  191.  
  192. /**************************************************************************/
  193. /*                      sort the list in preparation                      */
  194. /**************************************************************************/
  195.  
  196.    if show('L','rexxtricks.library') then do    /* use tricks library     */
  197.       call QSORT(archlist)                   /* sort by name, line number */
  198.    end
  199.    else do                                   /* use QuickSort format      */
  200.       call QSORT(1, archlist.0, archlist)      /* sort by name, number    */
  201.    end 
  202.  
  203.    radio ID SQUIT 
  204.    if result~="Continue" then signal ProcessArchsEnd
  205.  
  206. /**************************************************************************/
  207. /*              Loop thru mail verifying nothing has changed              */
  208. /*          do it in reverse order to keep from rearranging list          */
  209. /**************************************************************************/
  210.  
  211.    do i=archlist.0 to 1 by -1                /* process in reverse order  */
  212.       radio ID SQUIT 
  213.       if result~="Continue" then leave    /* skip remaining & do cleanup  */
  214.       anum=word(Archlist.i,1)
  215.       anum=strip(anum,'L','0')
  216.       if anum='' then anum=0
  217.       mnum=word(Archlist.i,2)
  218.       mnum=strip(mnum,'L','0')
  219.       if mnum='' then mnum=0
  220.       file=word(Archlist.i,3)
  221.       subj=subword(Archlist.i,4)
  222.       Updlist.i=anum
  223.       Updlist.i.1=mnum
  224.       Updlist.i.1.1=file
  225.       Updlist.i.1.1.1=subj
  226.       Address YAM 'setfolder 'anum           /* goto folder               */
  227.       Address YAM 'setmail 'mnum             /* set to mail               */
  228.       Address YAM "getmailinfo file"         /* verify filename           */
  229.       xfile=result
  230.       fullfile=xfile                         /* copy complete path/fn     */
  231.       xlen=length(file)
  232.       xfile=right(xfile,xlen)
  233.       Address YAM "getmailinfo subject"      /* verify subject            */
  234.       xsubj=result      
  235.       xsubj=translate(xsubj,' ',',')
  236.       if file~=xfile | xsubj~=subj then do
  237.          Updlist.i.1.1.1.1='\033berror'
  238.       end 
  239.       else do
  240.          if anum=0 then do               /* use ARCHIVE cmd for Incoming  */
  241.             Address YAM "mailarchive " targanum
  242.             Updlist.i.1.1.1.1='\033barchived'
  243.          end
  244.          else do                             /* Handle others             */
  245.                Call MoveIt
  246.          end
  247.       end
  248.    end
  249.    
  250. /**************************************************************************/
  251. /*                    Update target and source folders                    */
  252. /**************************************************************************/
  253.  
  254.    infotext='\033nUpdating Folder Indexes...'
  255.    text ID STEXT LABEL infotext
  256.  
  257.    Address YAM 'setfolder 'targanum          /* set to target folder      */
  258.    Address YAM 'mailupdate'                  /* update the index          */
  259.    oldarch=missing                           /* level break control       */
  260.    do i=1 to Updlist.0
  261.       if Updlist.i~=oldarch then do
  262.          Address YAM 'setfolder ' Updlist.i  /* goto folder               */
  263.          Address YAM 'mailupdate'            /* update the index          */
  264.          oldarch=Updlist.i
  265.       end
  266.    end
  267.  
  268. /**************************************************************************/
  269. /*                   Update list of mail archived/moved                   */
  270. /**************************************************************************/
  271.  
  272.    infotext='\033nUpdating Mail Status...'
  273.    text ID STEXT LABEL infotext
  274.  
  275.    do i=1 to Updlist.0                       /* display status messages   */
  276.       do j=0 to mcnt-1
  277.          list ID MLST POS j
  278.          mline=result
  279.          if mline='' then break
  280.          parse var mline arch ',' from ',' subj ',' mfor ',' mnum ',' anum ',' file
  281.          if Updlist.i=anum & Updlist.i.1=mnum then do
  282.             if Updlist.i.1.1.1.1~=missing then arch=Updlist.i.1.1.1.1
  283.             mline=arch||','||from||','||subj||','||mfor||','||mnum||','||anum||','||file
  284.             list ID MLST POS j STRING mline
  285.             iterate i
  286.          end
  287.       end
  288.    end
  289.  
  290. ProcessArchsEnd:
  291.  
  292.    window ID YTINF CLOSE
  293.  
  294. Return
  295.  
  296. /**************************************************************************/
  297. /* Find the LAST filename in the target dir, calculate new name, do a DOS */
  298. /* COPY command for output and a DOS delete command for the input.        */
  299. /* !! DON'T USE 'i' as a pointer in this routine                          */
  300. /**************************************************************************/
  301. MoveIt:
  302.  
  303.     targfn=right(date('I'),5,'0')
  304.  
  305.    dirlist=showdir(targdir,'FILE')
  306.    highfile='.index'
  307.    do filecnt=1 to words(dirlist)
  308.       if word(dirlist,filecnt) > highfile then do
  309.          highfile=word(dirlist,filecnt)
  310.       end
  311.    end
  312.  
  313.    highname=substr(highfile,1,5)
  314.    highext=substr(highfile,7,3)
  315.  
  316.    if targfn>highname then do
  317.       highname=targfn
  318.       highext='001'
  319.    end
  320.    else do
  321.       highext=highext+1
  322.       highext=right(highext,3,'0')
  323.    end   
  324.  
  325.    if highext='000' then do                    /* gone over 999           */
  326.       highname=right(highname+1,5,'0')         /* use next days date      */
  327.       highext='001'                            /* new series              */
  328.    end
  329.  
  330.    Address Command 'Copy ' fullfile 'TO' targdir'/'highname'.'highext 'QUIET CLONE'
  331.    if rc=0 then do
  332.       Updlist.i.1.1.1.1='\033bmoved'
  333.       Address Command 'Delete ' fullfile 'QUIET'
  334.    end
  335.    else do
  336.       Updlist.i.1.1.1.1='\033berror'
  337.    end
  338.  
  339. Return
  340.  
  341. /**************************************************************************/
  342. /*              Make sure YAM  and YAMTOOLS are running. Show YAM.        */
  343. /**************************************************************************/
  344. CheckYAM:
  345.  
  346.    if ~show('p','YAMTOOLS') then do
  347.       errmsg='You need YAMTOOLS running to use YTArcMove'
  348.       say errmsg
  349.       exit
  350.    end
  351.  
  352.    if ~show('p','YAM') then do
  353.       errmsg='You need YAM running to use YTArcMove'
  354.       Call ErrorMsg
  355.       exit
  356.    end
  357.  
  358.    Address YAM 'info version'               /* check YAM's version        */
  359.    yamver=word(result,3)
  360.  
  361.    if left(yamver,3)~=goodver then do       /* only 1.3.x or lower valid  */
  362.       errmsg='This script is not valid for YAM 'yamver
  363.       Call ErrorMsg
  364.       exit     
  365.    end
  366.  
  367.    Address YAM 'show'                       /* uniconify YAM's screen     */  
  368.  
  369.     Address YAM 'info SCREEN'                /* get YAM's screen           */
  370.     screen=result
  371.     if screen='' then screen='Workbench'
  372.  
  373. Return
  374.  
  375. /******************************************************************************/
  376. /*  Display ERROR message and EXIT.                                           */
  377. /******************************************************************************/
  378. ErrorMsg:
  379.  
  380.    window ID YTINF CLOSE
  381.  
  382.    request ID ERRM GADGETS '"OK"' errmsg
  383.  
  384.    exit
  385.  
  386. Return
  387.  
  388. /******************************************************************************/
  389. /*  Display list of Archives for archive target selection.                    */
  390. /******************************************************************************/
  391. ArchWindow:
  392.  
  393.    window ID YTARC TITLE '"YAM Tools Archiver"',
  394.           COMMAND '"window ID YTARC close"' PORT YAMTOOLS,
  395.           ATTRS MUIA_Window_PublicScreen screen
  396.  
  397.         group
  398.          group
  399.                text LABEL "\033c\033bSelect Target Folder For Archiving"
  400.          endgroup
  401.          group 
  402.             list ID ARCHF COMMAND '"YTArcMove.rexx %s"', 
  403.                HELP help.ARCHF NODE node.ARCHF,
  404.                TITLE '"\033bYam Folder Name,\033bNumber,"',
  405.                INSERT NODUP, 
  406.                ATTRS MUIA_List_Format '"BAR,P=\033r,WEIGHT=0 MAXWIDTH=0 MINWIDTH=0"'
  407.          endgroup
  408.         endgroup
  409.  
  410.    endwindow
  411.  
  412. Return
  413.  
  414. /******************************************************************************/
  415. /*  Simple information/error message window.                                  */
  416. /******************************************************************************/
  417. InfoWindow:
  418.  
  419.    window ID YTINF TITLE '"YAM Archiver Info"' ATTRS MUIA_Window_PublicScreen screen,
  420.           MUIA_Window_SizeGadget FALSE MUIA_Window_DragBar FALSE,
  421.           MUIA_Window_DepthGadget FALSE
  422.  
  423.       group 
  424.          group 
  425.             text ID STEXT HELP help.STEXT  NODE node.STEXT LABEL infotext
  426.          endgroup
  427.          if showbusy then do
  428.             group
  429.                object CLASS '"Busy.mcc"' ATTRS MUIA_VertWeight 25
  430.             endgroup
  431.          end
  432.          if infobuttons ~='' then do
  433.             group HORIZ
  434.                group 
  435.                   space HORIZ 
  436.                endgroup
  437.                group 
  438.                   radio ID SQUIT HELP help.SQUIT  NODE node.SQUIT LABELS infobuttons
  439.                endgroup
  440.                group 
  441.                   space HORIZ 
  442.                endgroup
  443.             endgroup
  444.          end
  445.          else do
  446.             group 
  447.                space HORIZ 100
  448.             endgroup
  449.          end
  450.       endgroup
  451.    endwindow
  452.  
  453. Return
  454.  
  455. /**************************************************************************/
  456. /*                           End of Active Code                           */
  457. /**************************************************************************/
  458.